package xhq.com.test.extspring.listener;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import xhq.com.test.extspring.bean.model.MyBeanClass;
import xhq.com.test.extspring.bean.model.MyBeanClassTwo;

/**
 * @author hq_xu
 * @since 2021/1/26 10:12
 */
public class MySpringApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        System.out.println("from MySpringApplicationListener");
        var context = contextRefreshedEvent.getApplicationContext();
        System.out.println(context.getClass().getName());

        var myBean = context.getBean(MyBeanClass.class);
        var myName = myBean.getName();
        System.out.println(myName);
        System.out.println(myBean.hashCode());

        var myBean2 = context.getBean(MyBeanClassTwo.class);
        var myName2 = myBean2.getName();
        System.out.println(myName2);
    }
}
